package com.freedom.start.common.runner;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @Author: zhenggang.liu
 * @Date: 2020/4/16 16:17
 */
// @Component
public class MyApplicationRunner implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("=========自定义ApplicationRunner接口=========");
        // non option 意思是没有选项的参数,如:aaa
        args.getNonOptionArgs().forEach(System.out::println);
        System.out.println("-------------------------------");
        // option 带选项的参数，如：--server.port = 1234
        args.getOptionNames().forEach(s -> {
            System.out.println(s + " : " + args.getOptionValues(s));
        });
        System.out.println("-------------------------------");
        // 命令行原始参数
        for (String sourceArg : args.getSourceArgs()) {
            System.out.println("ApplicationRunner arg : " + sourceArg);
        }
        System.out.println("==========自定义ApplicationRunner接口========");

    }
}
